﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;


namespace TOSCOMMCreate
{
    public static class ClsTimeStamp
    {
        private static readonly DateTime _startDateTime = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        public static string getNowString()
        {
            long secondsSinceEpoch = (long)(DateTime.UtcNow - _startDateTime).TotalSeconds;
            string timeStamp = secondsSinceEpoch.ToString("X8");
            string result = Regex.Replace(timeStamp, ".{2}", "$0 ").Trim();
            return result;
        }

        public static DateTime getLocalTimeByStamp(string timestamp)
        {            
            timestamp = timestamp.Replace(" ", "");
            long date = Convert.ToInt64(timestamp, 16);
            DateTime dateTime = _startDateTime.AddSeconds(date);
            dateTime = dateTime.ToLocalTime();
            return dateTime;
        }

    }
}
